ModelSettings.dx      = 2*pi/100;
ModelSettings.L0      = pi;
ModelSettings.L       = 100;
ModelSettings.mode    = 200;
ModelSettings.FitTo   = 'meanR2';
ModelSettings.FittingTimeRange = 1000;
ModelSettings.W       = [0.10,0.15,0.20,0.25,0.30,0.35,0.40,0.45,0.50];
ModelSettings.nu      = [3.4941e-4 -9.6277e-7 1.1522e-7 -3.1824e-6 -7.0819e-7 -2.2166e-6 2.6946e-6 -3.374e-7 -5.1585e-7];
ModelSettings.sigma2  = [6.1298e-3 1.9592e-3 3.4054e-3 3.1876e-3 7.4906e-3 9.6178e-3 1.7936e-2 1.7489e-2 1.9078e-2];
ModelSettings.Rh      = [0.1002 0.1509 0.2021 0.2539 0.3057 0.3575 0.4093 0.4611 0.5129];
ModelSettings.K       = [0.99962 0.9955 0.9914 0.98833 0.98527 0.9822 0.97913 0.97607 0.973];
ModelSettings.Tau     = [10.074 7.6978 5.3215 4.7998 4.2782 3.7565 3.2348 2.7132 2.1915];
K_alpha = zeros(ModelSettings.mode,1);
K_beta  = zeros(ModelSettings.mode,1);
dx = ModelSettings.dx;
x = (1:100)*dx-pi;
for n=1:ModelSettings.mode
    h_sin = sin(n*x);
    dh_sin = h_sin;
    dh_sin(1) = h_sin(1)-h_sin(end);
    dh_sin(2:end) = diff(h_sin);
    K_alpha(n) = sum(dh_sin.^2)/(pi*dx^2);

    h_cos = cos(n*x);
    dh_cos = h_cos;
    dh_cos(1) = h_cos(1)-h_cos(end);
    dh_cos(2:end) = diff(h_cos);
    K_beta(n)  = sum(dh_cos.^2)/(pi*dx^2);    
end
ModelSettings.M2ModeWeighting=[K_alpha,K_beta];

ModelSettings.h = 0;
ModelSettings.rho = 0;
ModelSettings.meanAlpha2 = zeros(ModelSettings.mode,1);
ModelSettings.meanBeta2  = zeros(ModelSettings.mode,1);
ModelSettings.varAlpha2  = zeros(ModelSettings.mode,1);
ModelSettings.varBeta2   = zeros(ModelSettings.mode,1);
ModelSettings.meanR2     = model_CalMeanR2(ModelSettings);
ModelSettings.meanM2     = model_CalMeanM2(ModelSettings);
%%
% MPCsettings = MPC1xx_ini('model_settings1.mat');
% Settings.D_set   = 0.98;
% Settings.Fact_D  = 0.0;
% Settings.R2_set  = 40;
% Settings.Fact_r2 = 0.0;
% Settings.Ht_set  = 300;
% Settings.Fact_H  = 0.0;
% Settings.Fact_varR2 = 0.0;
% Settings.M2_set  = 0.5;
% Settings.M2_fact = 1.0;
% Settings.P       = 5;
% % Settings.m       = 20;
% Settings.dt      = 5;
% Settings.ub      = 0.45;
% Settings.lb      = 0.1;
% Settings.rt_dep  = 0.1;
% Settings.ControllerTypeID = 104;
% Settings.model = ModelSettings;
% Settings.costfun = @objfun;
% Settings.nonlcon = @nonlcon105;
% Settings.weight = [1.0,0.8,0.6,0.4,0.2];
% Settings.Input = {'alpha','beta','h','rho'};
% Settings.Ouput = {'W(layer/s'};